<?php

namespace IDock\Insurance\HBIC\Response;

use IDock\Http\Response;
use IDock\Printer\preInquiryPrinter;
use IDock\Printer\UnderwritingRecallPrinter;
use IDock\Printer\UploadFilePrinter;

class NonCarOrderInquiryResponse extends AllHBICResponse
{

    public function resolve(): Response
    {
        $body = $this->getBody();

        if ($body) {
            $xml = simplexml_load_string($body);
            $body = $this->objectToArray($xml);
            $errorCode = $body['HEAD']['RESULTCODE'] ?? '';
            $message = $body['HEAD']['RESULTINFO'] ?? '';
            $this->setBody($body);
            if ($errorCode != '0000') {
                $this->setError(  ($errorCode ?: '') .":".$message);
                return  $this;
            }
        }

        return $this;
    }

    public function printerInit(): Response
    {
        $printer = new preInquiryPrinter();
        $data = $this->getBody();
        $printer->argc['nonCarApplyNo'] = $data['BODY']['APPLYNO'] ?? '';
        $this->printer = $printer;
        return $this;
    }
}
